<!doctypehtml><html class="sidebar-visible no-js light"lang=en><head><meta charset=UTF-8><title>Using modules - Perl One-Liners Guide</title><meta content="text/html; charset=utf-8"http-equiv=Content-Type><meta content="Example based guide for text processing with Perl from the command line"name=description><meta content=width=device-width,initial-scale=1 name=viewport><meta content=#ffffff name=theme-color><meta content="Perl One-Liners Guide"property=og:title><meta content=website property=og:type><meta content="Example based guide for text processing with Perl from the command line"property=og:description><meta content=https://learnbyexample.github.io/learn_perl_oneliners/ property=og:url><meta content=https://raw.githubusercontent.com/learnbyexample/learn_perl_oneliners/main/images/perl_oneliners_ls.png property=og:image><meta content=1280 property=og:image:width><meta content=720 property=og:image:height><meta content=summary_large_image property=twitter:card><meta content=@learn_byexample property=twitter:site><link href="favicon.svg" rel=icon><link rel="shortcut icon"href="favicon.png"><link href="css/variables.css" rel=stylesheet><link href="css/general.css" rel=stylesheet><link href="css/chrome.css" rel=stylesheet><link href="FontAwesome/css/font-awesome.css" rel=stylesheet><link href="fonts/fonts.css" rel=stylesheet><link href="highlight.css" rel=stylesheet><link href="tomorrow-night.css" rel=stylesheet><link href="ayu-highlight.css" rel=stylesheet><link href="style.css" rel=stylesheet><body><script>var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";</script><script>try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }</script><script>var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('light')
            html.classList.add(theme);
            html.classList.add('js');</script><script>var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);</script><nav aria-label="Table of contents"class=sidebar id=sidebar><div class=sidebar-scrollbox><ol class=chapter><li class="chapter-item expanded affix"><a href="cover.html">Cover</a><li class="chapter-item expanded affix"><a href="buy.html">Buy PDF/EPUB versions</a><li class="chapter-item expanded"><a href="preface.html"><strong aria-hidden=true>1.</strong> Preface</a><li class="chapter-item expanded"><a href="one-liner-introduction.html"><strong aria-hidden=true>2.</strong> One-liner introduction</a><li class="chapter-item expanded"><a href="line-processing.html"><strong aria-hidden=true>3.</strong> Line processing</a><li class="chapter-item expanded"><a href="in-place-file-editing.html"><strong aria-hidden=true>4.</strong> In-place file editing</a><li class="chapter-item expanded"><a href="field-separators.html"><strong aria-hidden=true>5.</strong> Field separators</a><li class="chapter-item expanded"><a href="record-separators.html"><strong aria-hidden=true>6.</strong> Record separators</a><li class="chapter-item expanded"><a class=active href="using-modules.html"><strong aria-hidden=true>7.</strong> Using modules</a><li class="chapter-item expanded"><a href="multiple-file-input.html"><strong aria-hidden=true>8.</strong> Multiple file input</a><li class="chapter-item expanded"><a href="processing-multiple-records.html"><strong aria-hidden=true>9.</strong> Processing multiple records</a><li class="chapter-item expanded"><a href="two-file-processing.html"><strong aria-hidden=true>10.</strong> Two file processing</a><li class="chapter-item expanded"><a href="dealing-with-duplicates.html"><strong aria-hidden=true>11.</strong> Dealing with duplicates</a><li class="chapter-item expanded"><a href="perl-rename-command.html"><strong aria-hidden=true>12.</strong> Perl rename command</a><li class="chapter-item expanded"><a href="Exercise_solutions.html"><strong aria-hidden=true>13.</strong> Exercise Solutions</a></li><br><hr><li class="chapter-item expanded"><i class="fa fa-github"id=git-repository-button></i><a href=https://github.com/learnbyexample/learn_perl_oneliners>   Source code</a><li class="chapter-item expanded"><i class="fa fa-home"id=home-button></i><a href="../index.html">   My Blog</a><li class="chapter-item expanded"><i class="fa fa-book"id=book-button></i><a href="../books.html">   My Books</a><li class="chapter-item expanded"><i class="fa fa-envelope"id=mail-button></i><a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>   learnbyexample weekly</a><li class="chapter-item expanded"><i class="fa fa-twitter"id=twitter-button></i><a href=https://twitter.com/learn_byexample>   Twitter</a></ol></div><div class=sidebar-resize-handle id=sidebar-resize-handle></div></nav><div class=page-wrapper id=page-wrapper><div class=page><div id=menu-bar-hover-placeholder></div><div class="menu-bar sticky bordered"id=menu-bar><div class=left-buttons><button aria-label="Toggle Table of Contents"title="Toggle Table of Contents"aria-controls=sidebar class=icon-button id=sidebar-toggle type=button><i class="fa fa-bars"></i></button><button aria-label="Change theme"title="Change theme"aria-controls=theme-list aria-expanded=false aria-haspopup=true class=icon-button id=theme-toggle type=button><i class="fa fa-paint-brush"></i></button><ul aria-label=Themes class=theme-popup id=theme-list role=menu><li role=none><button class=theme id=light role=menuitem>Light (default)</button><li role=none><button class=theme id=rust role=menuitem>Rust</button><li role=none><button class=theme id=coal role=menuitem>Coal</button><li role=none><button class=theme id=navy role=menuitem>Navy</button><li role=none><button class=theme id=ayu role=menuitem>Ayu</button></ul><button aria-label="Toggle Searchbar"title="Search. (Shortkey: s)"aria-controls=searchbar aria-expanded=false aria-keyshortcuts=S class=icon-button id=search-toggle type=button><i class="fa fa-search"></i></button></div><h1 class=menu-title>Perl One-Liners Guide</h1><div class=right-buttons><a aria-label=Blog href="../index.html" title=Blog> <i class="fa fa-home"id=home-button></i> </a><a aria-label=Twitter href=https://twitter.com/learn_byexample title=Twitter> <i class="fa fa-twitter"id=twitter-button></i> </a><a aria-label="Git repository"title="Git repository"href=https://github.com/learnbyexample/learn_perl_oneliners> <i class="fa fa-github"id=git-repository-button></i> </a></div></div><div class=hidden id=search-wrapper><form class=searchbar-outer id=searchbar-outer><input placeholder="Search this book ..."aria-controls=searchresults-outer aria-describedby=searchresults-header id=searchbar name=searchbar type=search></form><div class="searchresults-outer hidden"id=searchresults-outer><div class=searchresults-header id=searchresults-header></div><ul id=searchresults></ul></div></div><script>document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });</script><div class=content id=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=using-modules><a class=header href="using-modules.html#using-modules">Using modules</a></h1><p>By default, Perl provides plenty of standard modules. And there are many more third-party modules available for a wide variety of use cases. This chapter will discuss the <code>-M</code> command line option and show some examples with the standard and third-party modules. You'll also see how to convert one-liners to a full fledged script file.<blockquote><p><img alt=info src="images/info.svg"> The <a href=https://github.com/learnbyexample/learn_perl_oneliners/tree/main/example_files>example_files</a> directory has all the files used in the examples.</blockquote><h2 id=standard-modules><a class=header href="using-modules.html#standard-modules">Standard modules</a></h2><p>See <a href=https://perldoc.perl.org/modules>perldoc: modules</a> for a complete list of built-in modules. Quoting from <a href=https://perldoc.perl.org/perlrun#-m%5B-%5Dmodule>perldoc: -m and -M options</a>:<blockquote><p><code>-Mmodule</code> executes <code>use module ;</code> before executing your program. This loads the module and calls its <code>import</code> method, causing the module to have its default effect, typically importing subroutines or giving effect to a pragma. You can use quotes to add extra code after the module name, e.g., <code>'-MMODULE qw(foo bar)'</code>.<p>A little builtin syntactic sugar means you can also say <code>-mMODULE=foo,bar</code> or <code>-MMODULE=foo,bar</code> as a shortcut for <code>'-MMODULE qw(foo bar)'</code>. This avoids the need to use quotes when importing symbols. The actual code generated by <code>-MMODULE=foo,bar</code> is <code>use module split(/,/,q{foo,bar})</code>. Note that the <code>=</code> form removes the distinction between <code>-m</code> and <code>-M</code>; that is, <code>-mMODULE=foo,bar</code> is the same as <code>-MMODULE=foo,bar</code></blockquote><p>The <code>List::Util</code> module has handy functions for array processing. See <a href=https://perldoc.perl.org/List::Util>perldoc: List::Util</a> for documentation. Here are some examples with <code>max</code>, <code>product</code> and <code>sum0</code>.<pre><code class=language-bash># same as: perl -F, -anE 'BEGIN{use List::Util qw(max)} say max @F'
$ echo '34,17,6' | perl -MList::Util=max -F, -anE 'say max @F'
34

$ echo '34,17,6' | perl -MList::Util=product -F, -anE 'say product @F'
3468

# 'sum0' returns '0' even if the array is empty, whereas 'sum' returns 'undef'
$ echo '3.14,17,6' | perl -MList::Util=sum0 -F, -anE 'say sum0 @F'
26.14
</code></pre><p>Here are some examples for <code>shuffle</code>, <code>sample</code> and <code>uniq</code>.<pre><code class=language-bash>$ s='floor bat to dubious four'
$ echo "$s" | perl -MList::Util=shuffle -lanE 'say join ":", shuffle @F'
bat:four:dubious:floor:to

$ echo 'dragon' | perl -MList::Util=shuffle -F -lanE 'say shuffle @F'
rogdan

# similar to shuffle, but can specify the number of elements needed
$ echo "$s" | perl -MList::Util=sample -lanE 'say join ":", sample 2, @F'
dubious:bat

$ s='3,b,a,3,c,d,1,d,c,2,2,2,3,1,b'
# note that the input order of elements is preserved
$ echo "$s" | perl -MList::Util=uniq -F, -lanE 'say join ",",uniq @F'
3,b,a,c,d,1,2
</code></pre><p>Here's an example for <code>base64</code> encoding and decoding. See <a href=https://perldoc.perl.org/MIME::Base64>perldoc: MIME::Base64</a> for documentation.<pre><code class=language-bash>$ echo 'hello world' | base64
aGVsbG8gd29ybGQK

$ echo 'hello world' | perl -MMIME::Base64 -ne 'print encode_base64 $_'
aGVsbG8gd29ybGQK
$ echo 'aGVsbG8gd29ybGQK' | perl -MMIME::Base64 -ne 'print decode_base64 $_'
hello world
</code></pre><h2 id=third-party-modules><a class=header href="using-modules.html#third-party-modules">Third party modules</a></h2><p>The <strong>Comprehensive Perl Archive Network</strong> (<a href=https://www.cpan.org/>https://www.cpan.org/</a>) has a huge collection of modules for various use cases. Before installing a new module, first check if the module is already installed or not:<pre><code class=language-bash># output shown here is modified for presentation purposes
$ perl -MText::CSV -e ''
Can't locate Text/CSV.pm in @INC (you may need to install the Text::CSV module)
(@INC entries checked: &LTlist of paths>).
BEGIN failed--compilation aborted.
</code></pre><p>If you are using the Perl version that came installed with your operating system, check if you can install a module from your platform repository. Here's an example for Ubuntu:<pre><code class=language-bash># search for the Text::CSV module
$ apt-cache search perl text-csv
libspreadsheet-read-perl - reader for common spreadsheet formats
libtext-csv-encoded-perl - encoding-aware comma-separated values manipulator
libtext-csv-perl - comma-separated values manipulator (using XS or PurePerl)
libtext-csv-xs-perl - Perl C/XS module to process Comma-Separated Value files

# install the module of your choice
$ sudo apt install libtext-csv-xs-perl
</code></pre><p>The above process may fail to work with the Perl version that you manually installed or if a particular module isn't available from your platform repository. There are different options for such cases.<ul><li><a href=https://stackoverflow.com/q/65865/4082052>stackoverflow: easiest way to install a missing module</a> shows how to use the <code>cpan</code> command and has details for Windows platform too. You might need admin privileges.<li><a href=https://metacpan.org/pod/cpanm>metacpan: cpanm</a> is also often recommended<li><a href=https://metacpan.org/pod/Carton>metacpan: Carton</a> is a Perl module dependency manager (aka Bundler for Perl)</ul><h2 id=csv><a class=header href="using-modules.html#csv">CSV</a></h2><p>For robustly parsing CSV files, you can use <a href=https://metacpan.org/pod/Text::CSV>metacpan: Text::CSV</a> or <a href=https://metacpan.org/pod/Text::CSV_XS>metacpan: Text::CSV_XS</a> modules. <code>_XS</code> indicates a faster implementation, usually written in the <code>C</code> language. The <code>Text::CSV</code> module uses <code>Text::CSV_XS</code> by default and uses <code>Text::CSV_PP</code> (pure Perl implementation) if the <code>_XS</code> module isn't available.<p>Here's an example of parsing CSV input with embedded comma characters. <code>ARGV</code> is a special filehandle that iterates over filenames passed as command line arguments (see the <a href="multiple-file-input.html#multiple-file-input">Multiple file input</a> chapter for more details).<pre><code class=language-bash>$ s='eagle,"fox,42",bee,frog\n1,2,3,4'
# note that neither -n or -p is used here
$ printf '%b' "$s" | perl -MText::CSV_XS -E 'say $row->[1]
                     while $row = Text::CSV_XS->new->getline(*ARGV)'
fox,42
2
</code></pre><p>Here's an example with embedded newline characters. Quoting from the documentation:<blockquote><p><strong>Important Note:</strong> The default behavior is to accept only ASCII characters in the range from <code>0x20</code> (space) to <code>0x7E</code> (tilde). This means that the fields can not contain newlines. If your data contains newlines embedded in fields, or characters above <code>0x7E</code> (tilde), or binary data, you must set <code>binary => 1</code> in the call to <code>new</code>.</blockquote><pre><code class=language-bash>$ cat newline.csv
apple,"1
2
3",good
guava,"32
54",nice

$ perl -MText::CSV_XS -E '
        while($row = Text::CSV_XS->new({binary => 1})->getline(*ARGV))
        {say "$row->[1]\n-----"}' newline.csv
1
2
3
-----
32
54
-----
</code></pre><p>You can change the field separator using the <code>sep_char</code> option.<pre><code class=language-bash>
$ perl -MText::CSV_XS -E '
        while($row = Text::CSV_XS->new({sep_char => "\t"})->getline(*ARGV))
        {say join ",", @$row if $row->[0] eq "CSE"}' marks.txt
CSE,Surya,81
CSE,Amy,67
</code></pre><h2 id=json><a class=header href="using-modules.html#json">JSON</a></h2><p>Newer versions of Perl come with the <a href=https://perldoc.perl.org/JSON::PP>perldoc: JSON::PP</a> module, which is a pure Perl implementation. Use <a href=https://metacpan.org/pod/JSON::XS>metacpan: JSON::XS</a> for faster results. There's also <a href=https://metacpan.org/pod/Cpanel::JSON::XS>metacpan: Cpanel::JSON::XS</a>, which mentions the following reason:<blockquote><p>While it seems there are many JSON modules, none of them correctly handle all corner cases, and in most cases their maintainers are unresponsive, gone missing, or not listening to bug reports for other reasons.</blockquote><p>Here's a simple example of parsing JSON from a single line of input data.<pre><code class=language-bash>$ s='{"greeting":"hi","marks":[78,62,93]}'

# <> is same as &LTARGV>, here it helps to get a line of input
$ echo "$s" | perl -MCpanel::JSON::XS -E '$ip=decode_json <>; say $ip->{greeting}'
hi

$ echo "$s" | perl -MCpanel::JSON::XS -E '$ip=decode_json <>;
              say join ":", @{$ip->{marks}}'
78:62:93
</code></pre><p>For multiline input, use <code>-0777</code> (or set <code>$/ = undef</code> or <code>-g</code> with newer Perl versions) to pass the entire input content as single string. You can also create a shortcut to make it easier for one-liners.<pre><code class=language-bash># check if a shortcut is available
$ type pj
bash: type: pj: not found

# add this to your ~/.bashrc (or the file you use for aliases/functions)
$ pj() { perl -MCpanel::JSON::XS -0777 -E '$ip=decode_json <>;'"$@" ; }

$ s='{"greeting":"hi","marks":[78,62,93]}'

$ echo "$s" | pj 'say $ip->{greeting}'
hi
</code></pre><p>Here's another example.<pre><code class=language-bash>$ cat sample.json
{
    "fruit": "apple",
    "blue": ["toy", "flower", "sand stone"],
    "light blue": ["flower", "sky", "water"],
    "language": {
        "natural": ["english", "hindi", "spanish"],
        "programming": ["python", "kotlin", "ruby"]
    },
    "physics": 84
}

# order may be different than input as hash doesn't maintain key order
# process top-level keys not containing 'e'
$ pj 'for (keys %$ip){say "$_:$ip->{$_}" if !/e/}' sample.json
physics:84
fruit:apple

# process keys within 'language' key that contain 't'
$ pj '$"=","; while(($k,$v) = each %{$ip->{language}})
      {say "$k:@{$v}" if $k=~/t/}' sample.json
natural:english,hindi,spanish
</code></pre><p>Here's an example of converting possibly minified <code>json</code> input to a pretty printed output. You can use <code>json_pp</code> for <code>JSON::PP</code> and <code>json_xs</code> for <code>JSON::XS</code>.<pre><code class=language-bash>$ s='{"greeting":"hi","marks":[78,62,93],"fruit":"apple"}'

# same as: echo "$s" | perl -MCpanel::JSON::XS -e '
#          print Cpanel::JSON::XS->new->pretty->encode(decode_json <>)'
$ echo "$s" | cpanel_json_xs
{
   "fruit" : "apple",
   "greeting" : "hi",
   "marks" : [
      78,
      62,
      93
   ]
}
</code></pre><p>If you need to preserve order, see:<ul><li><a href=https://stackoverflow.com/q/38028559/4082052>stackoverflow: Hash::Ordered versus Tie::IxHash with JSON::XS encode</a><li><a href=https://stackoverflow.com/q/51366750/4082052>stackoverflow: decode and encode json preserving order</a></ul><h2 id=convert-one-liners-to-pretty-formatted-scripts><a class=header href="using-modules.html#convert-one-liners-to-pretty-formatted-scripts">Convert one-liners to pretty formatted scripts</a></h2><p>The <code>O</code> module can be used to convert one-liners to full fledged programs. See <a href=https://perldoc.perl.org/O>perldoc: O</a> for documentation. This is similar to the <code>-o</code> option provided by <code>GNU awk</code>.<p>Here's how the <code>-n</code> and <code>-p</code> options are implemented.<pre><code class=language-bash># note that input sources (stdin, filenames, etc) aren't needed here
$ perl -MO=Deparse -ne 'print if /at/'
LINE: while (defined($_ = readline ARGV)) {
    print $_ if /at/;
}
-e syntax OK

$ perl -MO=Deparse -pe 's/ /:/g'
LINE: while (defined($_ = readline ARGV)) {
    s/ /:/g;
}
continue {
    die "-p destination: $!\n" unless print $_;
}
-e syntax OK
</code></pre><blockquote><p><img alt=info src="images/info.svg"> You can use <code>-MO=qq,Deparse</code> if you don't want to see the <code>-e syntax OK</code> message.</blockquote><p>The <code>Deparse</code> output is very useful to debug record separator scripts.<pre><code class=language-bash>$ perl -MO=Deparse -l -0072 -ne 'print if /a/'
BEGIN { $/ = ":"; $\ = "\n"; }
LINE: while (defined($_ = readline ARGV)) {
    chomp $_;
    print $_ if /a/;
}
-e syntax OK

$ perl -MO=Deparse -00 -ne 'print if /it/'
BEGIN { $/ = ""; $\ = undef; }
LINE: while (defined($_ = readline ARGV)) {
    print $_ if /it/;
}
-e syntax OK
</code></pre><p>Here's an alternate way to specify some code to be executed after the <code>while</code> loop instead of using the <code>END</code> block, when the <code>-n</code> option is being used. This cannot be used with the <code>-p</code> option because it will disrupt the <code>continue</code> block.<pre><code class=language-bash>$ perl -MO=Deparse -ne 'print if /4/ }{ print "==> the end\n"'
LINE: while (defined($_ = readline ARGV)) {
    print $_ if /4/;
}
{
    print "==> the end\n";
}
-e syntax OK
</code></pre><p>Here's an example of saving the script to a file instead of displaying on the terminal.<pre><code class=language-bash>$ perl -MO=Deparse -ne 'print if /4/' > script.pl
-e syntax OK
$ cat script.pl
LINE: while (defined($_ = readline ARGV)) {
    print $_ if /4/;
}

$ perl script.pl table.txt
brown bread mat hair 42
yellow banana window shoes 3.14
</code></pre><blockquote><p><img alt=info src="images/info.svg"> <img alt=info src="images/info.svg"> If you have noted the <code>Deparse</code> output very carefully, you'll see that the <code>while</code> loop has a <code>LINE</code> label. So, you can use <code>next LINE</code> to move onto the next input record even if you are inside other loops and blocks.</blockquote><h2 id=modules-to-explore><a class=header href="using-modules.html#modules-to-explore">Modules to explore</a></h2><ul><li><a href=https://github.com/hachiojipm/awesome-perl>Awesome Perl</a> — curated list of awesome Perl5 frameworks, libraries and software<li><a href=https://bioperl.org/howtos/index.html>bioperl</a> — practical descriptions of BioPerl modules<li><a href=https://metacpan.org/pod/XML::LibXML>metacpan: XML::LibXML</a> — xml/html parsing<li><a href=https://metacpan.org/pod/String::Approx>metacpan: String::Approx</a> — fuzzy matching<li><a href=https://metacpan.org/pod/Tie::IxHash>metacpan: Tie::IxHash</a> — ordered associative arrays for Perl<li><a href=https://unix.stackexchange.com/q/310840/109046>unix.stackexchange: example for Algorithm::Combinatorics</a><li><a href=https://unix.stackexchange.com/q/319301/109046>unix.stackexchange: example for Text::ParseWords</a><li><a href=https://unix.stackexchange.com/q/280492/109046>unix.stackexchange: sort words by syllable count using Lingua::EN::Syllable</a><li><a href=https://stackoverflow.com/q/3258847/4082052>stackoverflow: regular expression modules</a></ul><h2 id=summary><a class=header href="using-modules.html#summary">Summary</a></h2><p>This chapter showed how to enable modules via the <code>-M</code> option and some examples for the standard and third-party modules. You also saw how to convert cryptic one-liners to full fledged Perl scripts using the <code>O</code> module.<h2 id=exercises><a class=header href="using-modules.html#exercises">Exercises</a></h2><blockquote><p><img alt=info src="images/info.svg"> The <a href=https://github.com/learnbyexample/learn_perl_oneliners/tree/main/exercises>exercises</a> directory has all the files used in this section.</blockquote><p><strong>1)</strong> For the given space separated words, display the max word determined by alphabetic order.<pre><code class=language-bash>$ s='let in bat xml me lion'

$ echo "$s" | ##### add your solution here
xml
</code></pre><p><strong>2)</strong> For the given space separated words, randomize the order of characters for each word.<pre><code class=language-bash>$ s='this is a sample sentence'

# sample randomized output shown here, could be different for you
$ echo "$s" | ##### add your solution here
htis si a melasp ecnnsete
</code></pre><p><strong>3)</strong> Use the <a href=https://metacpan.org/pod/XML::LibXML>metacpan: XML::LibXML</a> module to get the content of all tags named <code>blue</code> for the input file <code>sample.xml</code>. See <a href=https://grantm.github.io/perl-libxml-by-example/>grantm: Perl XML::LibXML by example</a> for a detailed book on the <code>XML::LibXML</code> module.<pre><code class=language-bash>$ cat sample.xml
&LTdoc>
    &LTgreeting type="ask">Hi there. How are you?&LT/greeting>
    &LTgreeting type="reply">I am good.&LT/greeting>
    &LTcolor>
        &LTblue>flower&LT/blue>
        &LTblue>sand stone&LT/blue>
        &LTlight-blue>sky&LT/light-blue>
        &LTlight-blue>water&LT/light-blue>
    &LT/color>
&LT/doc>

##### add your solution here
flower
sand stone
</code></pre><p><strong>4)</strong> Display the current time in the format shown below.<pre><code class=language-bash># output will be different for you
##### add your solution here
12-Sep-2023 11:01:14
</code></pre><blockquote><p><img alt=info src="images/info.svg"> See <a href=https://metacpan.org/pod/DateTime>metacpan: DateTime</a> for more comprehensive functions.</blockquote></main><nav aria-label="Page navigation"class=nav-wrapper><a aria-label="Previous chapter"class="mobile-nav-chapters previous"title="Previous chapter"aria-keyshortcuts=Left href="record-separators.html" rel=prev> <i class="fa fa-angle-left"></i> </a><a aria-label="Next chapter"class="mobile-nav-chapters next"title="Next chapter"aria-keyshortcuts=Right href="multiple-file-input.html" rel=next> <i class="fa fa-angle-right"></i> </a><div style="clear: both"></div></nav></div></div><nav aria-label="Page navigation"class=nav-wide-wrapper><a aria-label="Previous chapter"class="nav-chapters previous"title="Previous chapter"aria-keyshortcuts=Left href="record-separators.html" rel=prev> <i class="fa fa-angle-left"></i> </a><a aria-label="Next chapter"class="nav-chapters next"title="Next chapter"aria-keyshortcuts=Right href="multiple-file-input.html" rel=next> <i class="fa fa-angle-right"></i> </a></nav></div><script>window.playground_copyable = true;</script><script charset=utf-8 src="elasticlunr.min.js"></script><script charset=utf-8 src="mark.min.js"></script><script charset=utf-8 src="searcher.js"></script><script charset=utf-8 src="clipboard.min.js"></script><script charset=utf-8 src="highlight.js"></script><script charset=utf-8 src="book.js"></script><script src="sidebar.js"></script>